/**
 * Created by ray on 17-6-12.
 */


let baseUrl = 'http://121.40.178.164:4040/react-service/api';

const request = (api,method,body) => {

    let url = `${ baseUrl } ${ api }`;
    let isOk;
    return new Promise((resolve,reject) => {
        fetch(url, {
                method:method,
                headers:configure.Header,
                body
                })
                .then((response) => {
                   console.log(`isOk:${response.ok}`);
                   return response.json();
                })
                .then((responseData) => {
                    resolve(responseData);
                })
                .catch((error) => {
                    reject(error);
                });
    });

    // return fetch(url, {
    //     method:method,
    //     headers:configure.Header,
    //     body
    //     })
    //     .then((response) => {
    //         return response.json();
    //     })
    //     .then((json) => {
    //         alert(JSON.stringify(json));
    //         return JSON.stringify(json);
    //     })
    //     .catch((error) => {
    //         alert(`网络错误:${error}`)
    //     });
};

const apiStore = {
  picUrl:'http://121.40.178.164:4040',
  houseInfo:{
      houseList:'/houseInfo/getHouseList.do',
      houseDetial:'/houseInfo/getDetail.do',
      search:'/houseInfo/search.do'
  },
    systemConf:{
      banner:'/systemConf/getByParamKey.do',
  }
};

const configure = {
    POST:"POST",
    GET:"GET",
    Body:(param)=>(param),
    // Body:JSON.stringify({
    //
    // }),
    Header:{
        'Content-Type': 'application/x-www-form-urlencoded'
    }
};

export {
    request,
    apiStore,
    configure,
}